<?php
 
class pStructure_Position extends cFormElement {
	
	function getEditText($fieldName, $id, $value, cView $view)
	{
		$class = $this->getAttr("class")." ".$this->getAttr("field");
		
		if ($value===null || $value=='null' || $value=='') 
		{
			return '';
		}
		
		$s.="<fieldset class=\"position\"><legend><label for=\"$id\">".$this->getAttr("label")."</label></legend>
		<select name=\"".$fieldName."\" id=\"$id\" class=\"$class\" >";
		$rows = $this->cms->tree->selectRaw("type='folder' ORDER BY lft", $view);
		$rows = $this->cms->tree->levelizeRows($rows);

		foreach ($rows as $i=>$f)
		{	
			if (($f["rgt"]-$f["lft"])>1) {
				$mych="+";
			} else {
				$mych="-";
			}
			
			if ($value==$f["id"]) {
				$sel="selected=\"selected\""; 
			} else $sel="";
			
			$s.="<option value=\"".$f["id"]."\" $sel>".str_repeat("&nbsp;",$f['level']*3)." ".$mych." ".$f["name"]."</option>";
		}
		
		$s.="</select></fieldset>";
		return $s;
	}
	
	function getShowText($fieldName, $id, $value, cView $view)
	{
		if ($view->doctype=='raw' && $value=='') return 'NULL';
		else return parent::getShowText($fieldName, $id, $value, $view);
	}

}
 
?>